package com.collectplus.express.self;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import com.collectplus.express.BaseActivity2;
import com.collectplus.express.R;
import com.collectplus.express.logic.AppCache;
import com.collectplus.express.model.ExpressCompanyBean;
import com.collectplus.express.model.ReceiverBean;

import java.util.ArrayList;

import droid.frame.view.xlist.SListView;

/**
 * Created by joker on 2018/4/16.
 * 选择快递公司activity
 */
public class SelfExpressCompanyActivity extends BaseActivity2 {
    private ArrayList<ExpressCompanyBean> items = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        items = (ArrayList<ExpressCompanyBean>) getIntent().getSerializableExtra("items");
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.self_express_company_activity);
        super.findViewById();
        getAppTitle().setCommonTitle("选择快递公司");
        SListView mListview = (SListView) findViewById(R.id.listview);
        SelfExpressCompanyAdapter adapter = new SelfExpressCompanyAdapter(items, getContext(), mListview);
        mListview.setAdapter(adapter);
        mListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                ExpressCompanyBean item = (ExpressCompanyBean) parent.getAdapter().getItem(position);
                if (item != null) {
                    ReceiverBean cacheReceiver = AppCache.getParcelNew();
                    if (cacheReceiver == null) {
                        cacheReceiver = new ReceiverBean(1);
                        AppCache.setParcelNew(cacheReceiver);
                    }
                    cacheReceiver.setExpressCompanyId(item.getId());
                    cacheReceiver.setExpressCompanyName(item.getName());
                    setResult(Activity.RESULT_OK);
                    finish();
                }

            }
        });

    }

}
